package qeug.shsh.fi.fromPlugin;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;

public class SupplierFromPlugin extends AbstractFormPlugin {
    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        super.propertyChanged(e);
        String name = e.getProperty().getName();
        if (name.equals("qeug_admindivision")){
            for (ChangeData changeData : e.getChangeSet()) {
                Object newValue = changeData.getNewValue();
                if (newValue!=null){
                    DynamicObject value = (DynamicObject) newValue;
                    QFilter[] qFilters = new QFilter[]{new QFilter("id", "=", value.getLong("id"))};
                    DynamicObject assistantdata = BusinessDataServiceHelper.loadSingle("bos_assistantdata_detail", qFilters);
                    DynamicObject parent = assistantdata.getDynamicObject("parent");
                    QFilter[] q1 = new QFilter[]{new QFilter("id", "=", parent.getLong("id"))};
                    DynamicObject parentDynamicObject = BusinessDataServiceHelper.loadSingle("bos_assistantdata_detail", q1);
//                    DynamicObject parentDynamicObject = parent.getDynamicObject("parent");
                    this.getModel().setValue("qeug_assistantfield",parent);//地区
                    this.getModel().setValue("qeug_assistantfield1",parentDynamicObject.getDynamicObject("parent"));//国家
                }
            }

        }
    }
}
